package com.example.studentknowledgesys.dao;

import com.example.studentknowledgesys.entity.UserPoint;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserPointMapper {
    // 创建用户积分记录
    @Insert("INSERT INTO user_points(user_id, total_points) VALUES(#{userId}, #{totalPoints})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUserPoint(UserPoint userPoint);

    // 更新用户积分
    @Update("UPDATE user_points SET total_points = #{totalPoints}, " +
            "last_updated = NOW() WHERE user_id = #{userId}")
    int updateUserPoint(UserPoint userPoint);

    // 查询用户积分
    @Select("SELECT * FROM user_points WHERE user_id = #{userId}")
    UserPoint selectUserPointByUserId(Long userId);

    // 查询积分排行榜
    @Select("SELECT * FROM user_points ORDER BY total_points DESC LIMIT #{limit}")
    List<UserPoint> selectTopUsers(int limit);
    @Select("SELECT * FROM user_points order by total_points desc")
    List<UserPoint> selectAllUserPoints();
}
